package com.twu.biblioteca.user;

import com.twu.biblioteca.user.User;

import java.util.TreeSet;

public class UserAccounts {

    private TreeSet<User> userList;

    public UserAccounts() {
        userList = new TreeSet<User>();
        userList.add( new User("000-0001", "password", "User1", "Email1", "Phone1") );
        userList.add( new User("000-0002", "password", "User2", "Email2", "Phone2") );
    }

    public User validateUser(String libraryNumber, String password) {
        for( User user : userList){
            if(login(user, libraryNumber, password) ){
                return user;
            }
        }
        return null;
    }

    public boolean login(User user, String libraryNumber, String password){
        if ( user.getLibraryNumber().equals(libraryNumber) && user.getPassword().equals(password)){
            return true;
        }
        else {
            return false;
        }
    }
}
